/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package ultilities;

import java.util.List;

/**
 *
 * @author Nero
 */
public class FS_Ulti {

    public static int PaginationTotalPage(List<? extends Object> objectList, int item) {
        int totalPage = objectList.size() / item;
        if (objectList.size() % item != 0) {
            totalPage++;
        }
        return totalPage;
    }

    public static List<? extends Object> Pagination(List<? extends Object> objectList, int page, int item) throws Exception {
        if (objectList.isEmpty()) {
            throw new Exception("PAGE_EMPTY");
        }
        int startIndex = (page - 1) * item;
        int endIndex = startIndex + item;
        if (startIndex <= objectList.size()) {
            if (endIndex >= objectList.size()) {
                endIndex = objectList.size();
            }
            return objectList.subList(startIndex, endIndex);
        } else {
            throw new Exception("PAGE_NOT_FOUND");
        }
    }
}
